//
//  WBNavigationController.swift
//  wiboDemo
//
//  Created by shizb macbook air on 17/7/29.
//  Copyright © 2017年 YL. All rights reserved.
//

import UIKit

class WBNavigationController: UINavigationController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        navigationBar.isHidden=true
    }
//重写该方法，所有push动作都会调用这方法
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        if viewControllers.count > 0 {
            viewController.hidesBottomBarWhenPushed=true
            //判断是否是基类
            if let vc=viewController as?  WBBaseViewController{
                var title="返回"
                // 判断是否是第一个
                if childViewControllers.count==1 {
                    title=childViewControllers.first?.title ?? "返回"
                }
                //建立返回按钮
                vc.navItem.leftBarButtonItem=UIBarButtonItem(title: title, fontSize: 12, taget: self, action: #selector(goBack),isBack:true)
            }
        }
        super.pushViewController(viewController, animated: true)
        
    }
    
    func goBack() {
        popViewController(animated: true)
    }
 

}















